//
//  ZLHomeViewController.swift
//  MVVM微博
//
//  Created by AppleDev on 2017/7/15.
//  Copyright © 2017年 AppleDev. All rights reserved.
//

import UIKit

private let cellId = "cellId"

class ZLHomeViewController: ZLBaseViewController {

    lazy var statusList = [String]()
    


    func showFriends() {
         
        let vc = ZLDemoViewController()
        
        navigationController?.pushViewController(vc, animated: true)
        
    }
    
    override func loadData() {
        
        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 1) {
            for i in 0..<10 {
                if self.isPullup {
                    self.statusList.append("上拉\(i)")
                }else{
                    self.statusList.insert(i.description, at: 0)

                }
            }
            self.isPullup = false
            self.refreshControl?.endRefreshing()
            self.tableview?.reloadData()
        }
        
        
    }
}

extension ZLHomeViewController{
    
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        
        return statusList.count
        
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let tableviewCell = tableview?.dequeueReusableCell(withIdentifier: cellId, for: indexPath)
        
        tableviewCell?.textLabel?.text = statusList[indexPath.row]
        
        return tableviewCell!
        
        
    }
    
}

extension ZLHomeViewController{
    
    override func setupTableView() {
        
        super.setupTableView()
        item.leftBarButtonItem = UIBarButtonItem(title: "好友", fontSize: 16, target: self, action: #selector(showFriends))
        tableview?.register(UITableViewCell.self, forCellReuseIdentifier: cellId)
        
    }

}
